home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Wipes ƒ / Circle in.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  3.0 KB  |  100 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Circle in.c
  4.  
  5. Purpose:    Graphic effect from offscreen bitmap to main window (on
  6.             screen).  See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define    gap            4        /* difference between one radius and the next */
  32. #define CorrectTime 2
  33. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  34. #define theWindowWidth (boundsRect.right-boundsRect.left)
  35.  
  36. pascal short CircleIn(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  37.  
  38. /* Take a really big circle, then a slightly smaller circle (-gap), then
  39.    take the region in between them and copy that, then decrease the outer
  40.    circle radius by gap.  Thus: circle in, by successive donut-like copies. */
  41.  
  42. pascal short CircleIn(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  43. {
  44.     Rect            theRect;
  45.     int                cx, cy;
  46.     RgnHandle        curregion,lastregion,diffregion;
  47.     Point            zeroPoint;
  48.     int                StartRadius;
  49.     
  50.     zeroPoint.h=boundsRect.left;
  51.     zeroPoint.v=boundsRect.top;
  52.  
  53.     cx = theWindowWidth / 2;
  54.     cy = theWindowHeight / 2;
  55.     
  56.     lastregion=NewRgn();
  57.     StartRadius=0;
  58.     do
  59.     {
  60.         StartRadius+=2*gap;
  61.         theRect.left=cx-StartRadius;     /* circumscribing rectangle for outer circle */
  62.         theRect.right=cx+StartRadius;
  63.         theRect.top=cy-StartRadius;
  64.         theRect.bottom=cy+StartRadius;
  65.         OffsetRect(&theRect, boundsRect.left, boundsRect.top);
  66.         SetEmptyRgn(lastregion);
  67.         OpenRgn();
  68.             FrameOval(&theRect);        /* first circle */
  69.         CloseRgn(lastregion);
  70.     }
  71.     while (!PtInRgn(zeroPoint, lastregion));
  72.     
  73.     curregion=NewRgn();
  74.     diffregion=NewRgn();
  75.  
  76.     while (theRect.right-theRect.left>0)
  77.     {
  78.         StartTiming();
  79.         theRect.left+=gap;
  80.         theRect.right-=gap;
  81.         theRect.top+=gap;
  82.         theRect.bottom-=gap;
  83.         SetEmptyRgn(curregion);
  84.         OpenRgn();
  85.             FrameOval(&theRect);   /* inner circle */
  86.         CloseRgn(curregion);
  87.         DiffRgn(lastregion,curregion,diffregion);   /* donut we need */
  88.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  89.                 &boundsRect, &boundsRect, 0, diffregion);
  90.         CopyRgn(curregion,lastregion);    /* outer circle = inner circle */
  91.         TimeCorrection(CorrectTime);
  92.     }
  93.     
  94.     DisposeRgn(curregion);
  95.     DisposeRgn(lastregion);
  96.     DisposeRgn(diffregion);
  97.     
  98.     return 0;
  99. }
  100.